package com.zhongxia.controller;

import com.zhongxia.entity.Menu;
import com.zhongxia.entity.MenuVO;
import com.zhongxia.entity.Type;
import com.zhongxia.mapper.MenuMapper;
import com.zhongxia.mapper.TypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 废柴弟弟
 * @Date: 2020/3/4 8:26
 */
@RestController
@RequestMapping("menu")
public class MenuController {
    @Value("${server.port}")
    private String port;
    @Autowired
    private MenuMapper menuMapper;
    @Autowired
    private TypeMapper typeMapper;
    @GetMapping("index")
    public String index()
    {
        return this.port;
    }
    @GetMapping("findAll/{index}/{limit}")
    public MenuVO findAll(@PathVariable("index") int index, @PathVariable("limit") int limit)
    {
        return new MenuVO(0,"",menuMapper.count(),menuMapper.findAll(index, limit));
    }
    @GetMapping("count")
    public int count()
    {
        return menuMapper.count();
    }
    @DeleteMapping("deleteById/{id}")
    public void deleteById(@PathVariable("id") int id)
    {
        menuMapper.deleteById(id);
    }
    @GetMapping("findType")
    public List<Type> findType()
    {
        return typeMapper.findAll();
    }
    @PostMapping("save")
    public void save(@RequestBody Menu menu)
    {
        menuMapper.save(menu);
    }
    @GetMapping("findById/{id}")
    public Menu findById(@PathVariable("id") int id)
    {
        return menuMapper.findById(id);
    }
    @PutMapping("update")
    public void update(@RequestBody Menu menu)
    {
        menuMapper.update(menu);
    }
}
